{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle\n",
    "from datetime import datetime\n",
    "import pytz\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def show_result(uid):\n",
    "    raise Warning(\"不要调用这个方法，它已经被删除了。\")\n",
    "    return \n",
    "    with open(\"record.pkl\", \"rb\") as f:\n",
    "        x = pickle.load(f)\n",
    "    \"\"\"uid --> int\"\"\"\n",
    "   # j = 0\n",
    "    for i in x:\n",
    "        uname = i[uid][0]\n",
    "        followers = i[uid][1]\n",
    "        time = datetime.fromtimestamp(i[uid][2], pytz.timezone(\"Asia/Shanghai\"))\n",
    "        print(uname, followers,  time)\n",
    "       # j = i\n",
    "    \n",
    "def show_resultR(uid):\n",
    "    with open(\"record.pkl\", \"rb\") as f:\n",
    "        x = pickle.load(f)\n",
    "    \"\"\"uid --> int\"\"\"\n",
    "   # j = 0\n",
    "    for i in range(len(x)):\n",
    "        try:\n",
    "            uname = x[i][uid][0]\n",
    "            followers = x[i][uid][1]\n",
    "            if i == 0:\n",
    "                last_num_follower = followers\n",
    "                last_time_stamp = x[i][uid][2]\n",
    "            elif i > 0:\n",
    "                last_num_follower = x[i-1][uid][1]\n",
    "                last_time_stamp = x[i-1][uid][2]\n",
    "\n",
    "\n",
    "            timestamp = x[i][uid][2]\n",
    "            time = datetime.fromtimestamp(timestamp, pytz.timezone(\"Asia/Shanghai\"))\n",
    "        except KeyError:\n",
    "            continue\n",
    "        try:\n",
    "            print(\"{:<18}{:<+15d}{:<+15d}{:<10d}{:<10s}\".format( uname, \n",
    "                  int( (followers-last_num_follower)/(timestamp-last_time_stamp)*60*60*24 ),\n",
    "                                                       int( followers-last_num_follower ),\n",
    "                followers,  str(time) ))\n",
    "        except ZeroDivisionError:\n",
    "            print(uname, \"\\t\", \n",
    "                  followers-last_num_follower, \"\\t\"\n",
    "                   ,  followers, \"\\t\", time)\n",
    "       # j = i\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def show_log():\n",
    "    with open(\"debug.log\", \"r\") as f:\n",
    "        x = f.read()\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def search_result(name):\n",
    "    raise Warning(\"不要用这个方法，它已经被删除了。\")\n",
    "    return\n",
    "    with open(\"record.pkl\", \"rb\") as f:\n",
    "        x = pickle.load(f)\n",
    "    #j = 0\n",
    "    for i in x:\n",
    "        for k, v in i.items():\n",
    "            if name in v[0]:\n",
    "                uname = v[0]\n",
    "                followers = v[1]\n",
    "                time = datetime.fromtimestamp(v[2], pytz.timezone(\"Asia/Shanghai\"))\n",
    "                print(uname, followers, time)\n",
    "               # j = i\n",
    "            \n",
    "            \n",
    "def search_uid(name):\n",
    "    with open(\"record.pkl\", \"rb\") as f:\n",
    "        x = pickle.load(f)\n",
    "    \n",
    "    result = []\n",
    "        \n",
    "    for i in x:\n",
    "        for k, v in i.items():\n",
    "            if name == v[0]:\n",
    "                return k\n",
    "            elif name in v[0]:\n",
    "                return k\n",
    "            \n",
    "    raise RuntimeError(\"找不到\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def clear_log():\n",
    "    with open(\"debug.log\", \"w\") as f:\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "show_resultR(search_uid(\"some_up\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"record.pkl\", \"rb\") as f:\n",
    "        x = pickle.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pprint import pprint\n",
    "pprint(x[-50:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "datetime.fromtimestamp(1595493930.6504357, pytz.timezone(\"Asia/Shanghai\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}